//
//  WHYMainViewController.m
//  WHYWeibo-OC
//
//  Created by 王洪运 on 15/11/22.
//  Copyright © 2015年 王洪运. All rights reserved.
//

#import "WHYMainViewController.h"
#import "WHYHomeViewController.h"
#import "WHYMessageViewController.h"
#import "WHYDiscoverViewController.h"
#import "WHYProfileViewController.h"
#import "UIButton+Extension.h"

@interface WHYMainViewController ()
@property (strong, nonatomic) UIButton *composedButton;
@end

@implementation WHYMainViewController

#pragma mark - 视图生命周期方法
- (void)viewDidLoad {
    [super viewDidLoad];

    [self loadSubViewControllers];
    [self loadComposedButton];
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.tabBar bringSubviewToFront:self.composedButton];
}

#pragma mark - 加载撰写按钮
-(UIButton *)composedButton {
    if (_composedButton == nil) {
        _composedButton = [UIButton buttonWithImageName:@"tabbar_compose_icon_add" andBackIamgeName:@"tabbar_compose_button"];
    }
    return _composedButton;
}

-(void)loadComposedButton {
    [self.tabBar addSubview:self.composedButton];
    self.composedButton.frame = CGRectMake(149, 0, 77, 49);
    [self.composedButton addTarget:self action:@selector(clickComposedButton) forControlEvents:UIControlEventTouchUpInside];
}

-(void)clickComposedButton {
    NSLog(@"点击了撰写按钮");
}



#pragma mark - 加载子控制器
- (void) loadSubViewControllers {
    self.tabBar.tintColor = [UIColor orangeColor];
    
    UINavigationController *navHome = [self navigationControllerWithViewController:[WHYHomeViewController new] title:@"首页" imageName:@"tabbar_home"];
    UINavigationController *navMessage = [self navigationControllerWithViewController:[WHYMessageViewController new] title:@"消息" imageName:@"tabbar_message_center"];
    UINavigationController *navComposedButton = [UINavigationController new];
    UINavigationController *navDiscover = [self navigationControllerWithViewController:[WHYDiscoverViewController new] title:@"发现" imageName:@"tabbar_discover"];
    UINavigationController *navProfile = [self navigationControllerWithViewController:[WHYProfileViewController new] title:@"我" imageName:@"tabbar_profile"];
    
    self.viewControllers = @[navHome, navMessage, navComposedButton,navDiscover, navProfile];
    
}

- (UINavigationController *) navigationControllerWithViewController:(UIViewController *)vc title:(NSString *)title imageName:(NSString *)imageName {
    
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    
    return nav;
}


@end
